package com.dys.util;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @className: com.dys.util.StringToDateConverter
 * @description: 自定义日期类型转换器
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/10/26 18:22
 */
public class StringToDateConverter implements Converter<String, Date> {
    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public Date convert(String source) {
        Date parseDate = null;
        try {
            parseDate = sdf.parse(source);
        } catch (ParseException e) {
            throw new RuntimeException("日期转换异常：" + e);
        }
        return parseDate;
    }
}
